package com.wu.llpsw.event;


import com.wu.llpsw.data.levelData;
import com.wu.llpsw.networking.ModMessage;
import com.wu.llpsw.networking.packet.backYuanLiMaxPacket;
import com.wu.llpsw.networking.packet.backYuanLiNowPacket;
import com.wu.llpsw.yuanli.energy.yuanliManager;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.event.entity.player.PlayerXpEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = "wu")
public class xp {
    //玩家经验变化的事件
    @SubscribeEvent
    public static void xp_change(PlayerXpEvent.XpChange event){
        Player player=event.getPlayer();
        if(player!=null){
            levelData.setParam(player,player.experienceLevel);
            ModMessage.sendToPlayer(new backYuanLiMaxPacket(yuanliManager.getMaxYuanLi(player)),(ServerPlayer) player);
            ModMessage.sendToPlayer(new backYuanLiNowPacket(yuanliManager.getNowYuanLi(player)),(ServerPlayer)player);
        }
    }
}
